
Ext.define('DCApp.view.img.List', {
    extend: 'DCApp.view.List',
    alias: 'widget.imagelist',

    controller: 'imglist',
    viewModel: {
        type: 'imagelist'
    },
    listeners:{
    	afterrender:function(grid,opts){
    		var view = grid.getView();
			var tip = Ext.create('Ext.tip.ToolTip', {
			padding:0,
			style:"background-color:transparent;border:none",
			bodyStyle:"padding:0px;background-color:transparent",
			width:200,
			shadow:false,
			height:200,
			showDelay:50,
		    // The overall target element.
		    target: view.el,
		    // Each grid row causes its own separate show and hide.
		    delegate: view.itemSelector,
		    // Moving within the row should not hide the tip.
		    trackMouse: true,
		    // Render immediately so that tip.body can be referenced prior to the first show.
		    renderTo: Ext.getBody(),
		    listeners: {
		        // Change content dynamically depending on which element triggered the show.
		        beforeshow: function updateTipBody(tip) {
		        	//if(view.viewMode != 'default')
		        	//	return false;
		            //tip.update('Over company "' + view.getRecord(tip.triggerElement).get('id') + '"');
		        	var uri = view.getRecord(tip.triggerElement).get('uri'); 
		        	//var img_src = '/bat/servlet/fu?f='+uri+'&size=128&mr='+Math.random();
		        	if(uri==""||uri==null){
		        	    img_src="../imgs/no-photo-available.jpg";  
		        	}else{
		        		//img_src='../imgs/'+uri;
		        		img_src=uri;
		        	}		        	
		        	tip.body.dom.innerHTML = '<img border="1" src= "'+ img_src + '">';  
		        }
		    }
		});	   	
		}
    },
    tbar: ['->',{
    	xtype:'fileupload',
    	multiple:true,
    	accept:"image/png, image/jpeg",
    	entity_to:'Image'
	  },{
        text: '删除',
        handler: 'onRemove',
        hidden:true
    }
  	],
    columns: [
            {
                text     : '影像ID',
                dataIndex: 'id',
                filter: 'number'
            },
            {
                text     : '对象编号',
                dataIndex: 'objNo',
                filter: 'string'
            },
            {
                text     : '题名',
                dataIndex: 'imageName',
                width:300,
                filter: {
                    type: 'string',
                    itemDefaults: {
                        emptyText: 'Search for...'
                    }
                },
			   renderer1111:function(v,r,rec, rowIndex, columnIndex, store){
				   var uri = rec.get('uri');
		        	if(uri==""||uri==null){
		        	    img_src="../imgs/no-photo-available.jpg";  
		        	}else{
		        		//img_src='../imgs/'+uri;
		        		img_src=uri+'&size=90';
		        	}
				  	if(r){
				     	r.tdAttr="data-qtip=\"<img style='max-width:200px;max-height:200px;'  src='"+img_src+"'>\"";
				  	}
				    return v;
			    }
            },
            {
                text     : '光盘卷标',
                dataIndex: 'cdlabel',
                filter:'string'
            },
            {
                text     : '文件名',
                dataIndex: 'imgFile',
                width:150,
                filter:'string'
            },
            {
            	text:'影像来源',
            	dataIndex:'imageSource',
                filter: {
                    type: 'list',
                    idField:'abbr',
                    labelField:'name',
                    store:DCApp.Cfg.getDistinctStore('com.cl.entity.Image','imageSource')
                }
            },
            {
            	text:'有精细影像',
            	dataIndex:'isLivepicture',
            	renderer: function(value) {
		             if(value==1)
		             	return '有';
		             else if(value==0)
		             	return '无';
		             else return '';
		         },
                filter: {
                    type: 'list',
                    idField:'abbr',
                    labelField:'name',
                    store:DCApp.Cfg.getDistinctStore('com.cl.entity.Image','isLivepicture',false,
                function(st, records, successful, eOpts ){
                	for(var i=0; i<records.length; i++){
                		var rec=records[i];
                		switch(rec.get('abbr')){
                			case 0:
                				rec.set('name','无');
                			break;
                			case 1:
                				rec.set('name','有');
                			break;
                		}
                	}
                	console.log(st+'');
                })
                }
            },
            {
            	xtype: 'datecolumn',
                text     : '最近修改',
                dataIndex: 'lastUpdate',
                formatter: 'date("m/d/Y")',
                filter: true  // use dataIndex first then fallback to column type
            },
            {
                text     : 'uri',
                dataIndex: 'uri',
                filter:'string',
                width:450
            }
            
        ]
 });
